package com.hnpolice.xiaoke.carspeedcontrol.ui;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.hnpolice.xiaoke.carspeedcontrol.R;
import com.hnpolice.xiaoke.carspeedcontrol.view.MyDicsView;

public class MyDicsViewActivity extends AppCompatActivity {
    private MyDicsView dicsView;
    private TextView tv_start;
    private TextView tv_end;
    private EditText edt_dics;
    private int speed = 160;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_dics_view);
        initview();
        initStartOnclick();
        initEndOnclick();
    }

    private void initview() {
        dicsView = (MyDicsView) findViewById(R.id.dics_my_dics_view);
        tv_start = (TextView) findViewById(R.id.tv_my_dics_view_start);
        tv_end = (TextView) findViewById(R.id.tv_my_dics_view_end);
        edt_dics = (EditText) findViewById(R.id.edt_my_dics_view);
    }

    private void initStartOnclick() {
        tv_start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (edt_dics.getText().length() > 0) {
                    speed = Integer.valueOf(edt_dics.getText().toString());
                }
                if (speed > 360 || speed < 0) {
                    speed = 160;
                }
                dicsView.setSpeedStart(speed);
            }
        });
    }

    private void initEndOnclick() {
        tv_end.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dicsView.setSpeedEnd();
            }
        });
    }
}
